home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.sprintlink.net!news1!news
- From: rclark@iquest.net (Robert B. Clark)
- Subject: Re: Passing Parameters on Exit?
- X-Nntp-Posting-Host: ind-009-237-105.iquest.net
- Message-ID: <3118e50b.607140@news.iquest.net>
- Sender: news@iquest.net (News Admin)
- Organization: IQuest Internet, Inc.
- X-Newsreader: Forte Agent .99d/16.182
- References: <4f69hl$sp2@nic.umass.edu>
- Date: Wed, 7 Feb 1996 19:46:36 GMT
-
- On 6 Feb 1996 01:05:57 GMT, ksnella@twain.oit.umass.edu (Kenneth A
- Snella) wrote:
-
- >Is there any way to pass parameters out of a C program? I'm trying to
- >build a system that exits a C program and executes other programs (not
- >always C ones), but need to pass a couple of important items to the batch
-
- You can return an exit code (errorlevel) from main(). On DOS systems,
- this is an integer from 0 to 255. Let your batch file take advantage of
- this in order to determine which program is to be run next.
-
- This snippet returns errorlevel 1 when executed:
-
- /* foo.c */
- int main(void)
- {
- /* blah blah blah */
- return 1;
- }
-
- Your batch file might read something like this:
-
- foo
- if errorlevel 1 if not errorlevel 2 tw2002 /maint
- if not errorlevel 1 echo Returned errorlevel 0--no action requested.
-
- >way? It seems as though a call to the Borland C++ 3.1 function system()
- >would be able to SET an environment parameter, but it doesn't seem to
- >work. Any suggestions?
-
- Using system() to set an environment variable is next to worthless,
- because the variable only persists for the duration of *that*
- process--upon return to the parent process, the environment table is
- restored to its original content.
-
- In order to set an evar in the *master* environment table, you'd need to
- walk the MCB chain, find the master environment, then write your evar
- directly to it (after first making room if needed). This is fairly
- involved, and not always successful or portable across different OEM
- versions of DOS.
-
- I wrote some code to do this a while ago in Turbo Pascal, but haven't
- yet needed to port it to C. If you'd like to peruse the source code,
- grab it from your favorite Garbo site:
-
- 19442 Jan 18 01:00 ftp://garbo.uwasa.fi/pc/turbopas/envir10.zip
- --
- Robert B. Clark <rclark@iquest.net>
- "Be wary of strong spirits. It can make you shoot at tax collectors...
- and miss." --RAH
-